const wx2my = require('../../wx2my');

// pages/expense_calender/expense_calender.js
const app = getApp();
let page = 1;
let totalpage;
Page({
  data: {},
  onLoad: function (options) {},
  onReady: function () {},
  onShow: function () {
    page = 1;
    this.get_list();
  },

  get_list() {
    let that = this;
    app.wxRequest('recharge_details', {
      'token': wx2my.getStorageSync('token'),
      'page': page
    }, function (res) {
      console.log(res);

      if (res.data.code == 1) {
        let list = res.data.data.recharge.list;

        if (page == 1) {
          totalpage = res.data.data.recharge.totalpage;
        }

        that.setData({
          money: res.data.data.money,
          list: page == 1 ? list : that.data.list.concat(list),
          lock: totalpage <= page ? true : false
        });
      }
    });
  },

  onHide: function () {},
  onUnload: function () {},
  onPullDownRefresh: function () {},
  onReachBottom: function () {
    page++;

    if (!this.data.lock) {
      this.get_list();
    }
  },
  onShareAppMessage: function () {}
});